

local io = io
local string = string
local math = math
local table = table
local pairs = pairs
local ipairs = ipairs
local type = type
local assert = assert
local print = print
local tostring = tostring


module(...)

GenerateTexTab = function (tab)
  local tabstr = {'\n\\begin{tabular}{|'}
  local insert = function (str)
    table.insert(tabstr,str)
  end
  for i=1,#tab[1] do
     insert('l|')
  end
  insert('}\n \\hline \n')
  for n,lin in ipairs(tab) do
    insert(lin[1])
    for i=2,#lin do
      insert(' & '..tostring(lin[i]))
    end
    insert('\\\\ \n \\hline \n')
  end
  insert'\\end{tabular} \n \n'
  return table.concat(tabstr)
end

Mean= function (tab)
  assert(tab)
  assert(tab[1] and type(tab[1])=='number')
  local mean = 0
  for i,v in ipairs(tab) do
    mean = mean + v
  end
  return mean/#tab
end

StandardDeviation = function (tab)
  local mean = Mean(tab)
  local squares = {}
  for i,v in ipairs(tab) do
    squares[i] = (v-mean)*(v-mean)
  end
  return math.sqrt(Mean(squares)),mean
end

